﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Text;
using Metaspec;

// AST and entity visitors example.

namespace VisitorsExample
{
	class Program
	{
		static void Main(string[] args)
		{
			//creating project
			ICsProject project = ICsProjectFactory.create(project_namespace.pn_project_namespace);
			project.setBuildEntityModel(true);
			project.setParseDocumentationComments(true);

			//adding assemblies
			string assembly_path = Assembly.GetAssembly(typeof(object)).Location;
			byte[] assembly_buffer = File.ReadAllBytes(assembly_path);
			IExternalAssemblyModule module = IExternalAssemblyModuleFactory.create(assembly_buffer, assembly_path);
			project.addExternalAssemblyModules(new IExternalAssemblyModule[] { module }, false, null);

			//adding C# file
			string directory = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), @"..\..");
            string path = @"C:\Users\u164225\Documents\SolutionFramework\SolutionFramework\Generated_Code\SolutionFramework.Web.g.cs"; // Path.Combine(directory, "Test.cs");
			char[] buffer = File.ReadAllText(path).ToCharArray();
			ICsFile file = ICsFileFactory.create(buffer, path);
			project.addFiles(file);

			//parsing
			project.parse(true, false);

            var unit = (CsCompilationUnit) file.getCompilationUnit();
            var _class = (CsClass) unit.declarations[0];

			//find low-level code
			MyAstVisitor myAstVisitor = new MyAstVisitor();
            //file.getCompilationUnit().visit(myAstVisitor);

			//collect statistics
			MyEntityVisitor myEntityVisitor = new MyEntityVisitor();
            //project.getNamespace().visit(myEntityVisitor);
			myEntityVisitor.print();

			Console.ReadLine();
		}
	}
}
